<?php
namespace App\Repositories;

use App\Core\Node;
use App\Traits\SingletonTrait;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
class CmsCategoryRepository extends AbstractRepository
{
    use SingletonTrait;
    public function model()
    {
        return 'App\\Model\\CmsCategory';
    }

    public function view($top=false,$line=true)
    {
        $node = new Node();
        return $node->view($this,$top,$line);
    }

    public function store($data)
    {
        $node = new Node();
        $model = isset($data['id'])&&$data['id']?$this->getById($data['id']):new $this->model();
        $model->fill($data);
        $result = $node->store($this,$model);
        if($result['success']){
            return $this->success($result['data']);
        }
        return $this->error($result['msg']);
    }

    public function delete($id)
    {
        $node = new Node();
        $model = $this->getById($id);
        $result = $node->delete($this,$model);
        if($result['success']){
            return $this->success([]);
        }
        return $this->error('删除失败');
    }
}